<!-- 搜索表单 -->
<template>
  <div class="searchContainer">
    <el-card class="box-card"
             shadow="never">

      <!-- 订单状态 -->
      <!-- <div class="selectTime flex-align-center">
        <div class="orderStatus">订单状态:</div>
        <ul class="timeTab"
            v-for="(item, index) in orderStatusArr"
            :key="index">
          <li :class="[currentIndex == index ? 'active' : '']"
              @click="switchTimeTab(index,item.id)">{{ item.name }}</li>
        </ul>
      </div> -->

      <el-form label-width="100px"
               class="ele-form-search"
               ref="form"
               @keyup.enter.native="search"
               @submit.native.prevent>
        <el-row :gutter="15">

          <el-col :lg="6"
                  :md="12">
            <el-form-item label="创建者电话:">
              <el-input clearable
                        v-model="where.phone"
                        placeholder="请输入创建者电话" />

            </el-form-item>
          </el-col>
          <el-col :lg="6"
                  :md="12">
            <el-form-item label="搭子标题:">
              <el-input clearable
                        v-model="where.title"
                        placeholder="请输入搭子标题" />

            </el-form-item>
          </el-col>
          <el-col :lg="6"
                  :md="12">
            <el-form-item label="搭子创建者:">
              <el-input clearable
                        v-model="where.nickname"
                        placeholder="请输入搭子创建者" />

            </el-form-item>
          </el-col>

          <el-col :lg="6"
                  :md="12">
            <el-form-item label="当前状态:"
                          prop="status">
              <el-select clearable
                         class="ele-block"
                         v-model="where.status"
                         placeholder="请选择">
                <el-option label="全部"
                           :value="0" />
                <el-option label="待审核"
                           :value="1" />
                <el-option label="已上架"
                           :value="2" />
                <el-option label="下架"
                           :value="3" />

                <el-option label="过期"
                           :value="4" />
                <el-option label="完成"
                           :value="5" />
                <el-option label="驳回"
                           :value="7" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="6"
                  :md="12">
            <el-form-item label="创建时间:"
                          prop="dateRange">
              <el-date-picker v-model="where.dateRange"
                              type="datetimerange"
                              unlink-panels
                              range-separator="至"
                              start-placeholder="开始时间"
                              end-placeholder="结束时间"
                              :default-time="['00:00:00', '23:59:59']"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              class="ele-fluid" />
            </el-form-item>
          </el-col>
          <el-col :lg="6"
                  :md="12">
            <div class="ele-form-actions">
              <el-button type="primary"
                         icon="el-icon-search"
                         class="ele-btn-icon"
                         @click="search">
                查询
              </el-button>

              <el-button @click="reset('form')">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>
<script>

import { orderStatusArr } from '../constant/constant';
import { categoryList } from '../constant/constant';
export default {
  name: 'SystemUser',
  components: {
    // RegionsSelect
  },
  data () {
    // 默认表单数据
    const defaultWhere = {


      phone: '',
      dateRange: '',
      nickname: '',
      status: ''


    };
    return {
      categoryList,
      orderStatusArr,
      // 表单数据
      where: {
        ...defaultWhere
      },
      // 当前状态
      currentIndex: '0',
      sumbitForm: {},
      canRun: false,
      serviceCategoriesList: [],
      paymentMethodList: [
        {
          value: '1',
          label: '余额支付'
        },
        {
          value: '2',
          label: '微信'
        },

      ]
    };
  },
  props: {
    typeList: Array,
    oemList: {
      type: Array,
      default: () => []
    },
    secondaryList: {
      type: Array,
      default: () => []
    },
    currentPlatform: {
      type: String,
      default: ''
    }
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  methods: {
    // status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
    switchTimeTab (index, id) {
      this.currentIndex = index;
      if (id == 0) {
        this.sumbitForm.status = 0;

        this.$emit('search', this.sumbitForm);
      } else {
        this.sumbitForm.status = id;

        this.$emit('search', this.sumbitForm);
      }
    },
    /* 搜索 */
    search () {
      for (const key in this.where) {
        if (key == 'dateRange') {
          let startTime = this.where[key]?.[0];
          let endTime = this.where[key]?.[1];
          this.sumbitForm['start_time'] =
            startTime == undefined ? '' : startTime;
          this.sumbitForm['end_time'] =
            endTime == undefined ? '' : endTime;
        } else if (key == 'orderAmount') {
          this.sumbitForm['startOrderAmount'] =
            this.where[key].startOrderAmount == undefined
              ? ''
              : this.where[key].startOrderAmount;
          this.sumbitForm['endOrderAmount'] =
            this.where[key].endOrderAmount == undefined
              ? ''
              : this.where[key].endOrderAmount;
        } else {
          this.sumbitForm[key] = this.where[key];
        }
      }

      //   console.log(this.sumbitForm)
      this.$emit('search', this.sumbitForm);
    },
    async getCategoriesList (val) {
      console.log(val)
      this.where.payMethod = val
      //   if (val) {
      //     console.log(val);
      //     const res = await siteCategoriesList({
      //       limit: 10,
      //       page: this.pageNum,
      //       siteId: this.$store.state.site.info.id
      //     });

      //     const agentList = res.list.map((item) => {
      //       return {
      //         label: item.classificationName,
      //         value: item.id
      //       };
      //     });
      //     console.log(agentList);
      //     this.serviceCategoriesList = agentList;
      //   }
    },

    loadMoreAgent () {
      this.throttle(this.task, 1000)();
    },
    throttle (fun, timeout) {
      this.canRun = true;
      return () => {
        // 如果是true 就不走这
        if (!this.canRun) return;
        this.canRun = false;
        setTimeout(() => {
          fun();
          this.canRun = true;
        }, timeout);
      };
    },
    /*  重置 */
    reset (formName) {
      this.$refs[formName].resetFields();

      this.where = {}
      this.sumbitForm = {};
      this.currentIndex = 0
      this.$emit('search', this.sumbitForm);
    }
  }
};
</script>
<style lang="less" scoped>
.selectTime {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .timeTab {
    display: flex;
    align-items: center;
    margin-right: 20px;
    li {
      list-style-type: none;
      display: block;
      width: 110px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border: 1px solid #d9d9d9;
      border-radius: 10px;
    }
    .active {
      width: 110px;
      height: 38px;
      border-radius: 6px;
      background: #1890ff;
      color: #fff;
      text-align: center;
      line-height: 38px;
    }
  }
  .orderStatus {
    min-width: 77px;
    height: 34px;
    font-size: 14px;
    line-height: 34px;
  }
  .filterDate {
    text-align: center;
    line-height: 34px;
    width: 90px;
    height: 34px;
    font-size: 14px;
    border-radius: 2px 0px 0px 2px;
    border: 1px solid #d9d9d9;
    border-right: none;
  }
  .ele-fluid {
    width: 300px !important;
  }
}
.searchContainer {
  padding-bottom: 15px;
}
/deep/ .el-form-item__label {
  text-align: inherit;
}
.navList {
  margin-bottom: 25px;
  font-weight: 700;
}
</style>
